/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sunrise.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author Andrea
 */
@Entity
@NamedQueries({
    @NamedQuery(name = InvitationRequest.findByRecipient, query = "SELECT i FROM InvitationRequest i WHERE i.recipient= :recipient and i.viewed=false"),
    @NamedQuery(name = InvitationRequest.findByRecipientAndEvent, query = "SELECT i FROM InvitationRequest i WHERE i.recipient= :recipient and i.event = :event"),
    @NamedQuery(name = InvitationRequest.findByEvent, query = "SELECT i FROM InvitationRequest i WHERE i.event = :event")

})

public class InvitationRequest implements Serializable {

    private static final long serialVersionUID = 1L;
    public static final String findByRecipient = "InvitationRequest.findByRecipientId";
    public static final String findByRecipientAndEvent = "InvitationRequest.findByRecipientAndEvent";
    public static final String findByEvent = "InvitationRequest.findByEvent";

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne
    private Event event;

    @ManyToOne
    private User recipient;

    private boolean accepted;

    private boolean viewed;

    public InvitationRequest() {
        this.accepted = false;
        this.viewed = false;
    }

    public InvitationRequest(User recipient, Event event) {
        this.recipient = recipient;
        this.event = event;
        this.accepted = false;
        this.viewed = false;
    }
    
    public InvitationRequest(User recipient, Event event, Boolean accepted, Boolean viewed) {
        this.recipient = recipient;
        this.event = event;
        this.accepted = accepted;
        this.viewed = viewed;
    }

    public static List<InvitationRequest> buildWithInviteesAndEvent(List<User> invitees, Event e) {
        List<InvitationRequest> invitationRequests = null;

        if (invitees != null) {
            invitationRequests = new ArrayList<>();
            for (User user : invitees) {
                invitationRequests.add(new InvitationRequest(user, e));
            }
        }
        
        return invitationRequests;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public User getRecipient() {
        return recipient;
    }

    public void setRecipient(User recipient) {
        this.recipient = recipient;
    }

    public boolean isAccepted() {
        return accepted;
    }

    public void setAccepted(boolean accepted) {
        this.accepted = accepted;
    }

    public boolean isViewed() {
        return viewed;
    }

    public void setViewed(boolean viewed) {
        this.viewed = viewed;
    }
}
